import request from '@/utils/http/request'

// 定义保存医院设置的数据类型
export type HospitalSetSaveData = {
    apiUrl: string,
    contactsName: string,
    contactsPhone: string,
    hoscode: string,
    hosname: string,
    id?: number,
    isDeleted?: number,
    signKey: string,
    status: number,

}
// 定义获取医院数据的类型
export type HospitalSetData = {
    id: number,
    isDeleted?: number,
    hosname: string,
    hoscode: string,
    apiUrl: string,
    signKey: string,
    contactsName: string,
    contactsPhone: string,
    status: number
}

export type HospitalSetListData = HospitalSetData[]
// 定义获取分页列表的参数数据类型
export interface HospitalPageListData {
    page?: number,
    limit?: number,
    hosname?: string,
    hoscode?: string
}
// 定义返回的医院设置列表的数据类型
export type HospitalListData = {
    current: number
    hitCount: boolean
    pages: number
    records: HospitalSetListData
    searchCount: boolean
    size: number
    total: number
}


// 医院设置的接口
export default {
    // DELETE /admin/hosp/hospitalSet/batchRemove
    // 根据id列表批量删除医院设置
    deleteHospitalSet(idList: number[]) {
        // console.log(idList);
        // 函数调用的方式的data我们不需要加 {} 因为我们需要的是一个数组，而不是一个对象里面的某个属性是数组
        return request({
            url: '/admin/hosp/hospitalSet/batchRemove',
            data: idList,
            method: 'delete'
        })
    },
    // GET /admin/hosp/hospitalSet/get/{id}
    // 根据id查找医院设置
    getHospitalSet(id: string) {
        return request.get<any, HospitalSetData>(`/admin/hosp/hospitalSet/get/${id}`)
    },

    // DELETE /admin/hosp/hospitalSet/remove/{id}
    // 删除单个医院设置
    removeHospitalSet(id: string) {
        return request.delete<any, any>(`/admin/hosp/hospitalSet/remove/${id}`)
    },
    // HospitalSet
    // POST /admin/hosp/hospitalSet/save
    // 新增医院设置
    // PUT /admin/hosp/hospitalSet/update
    // 修改医院设置

    // 新增医院设置 //  修改医院设置
    saveHospitalSet(hospitalInfo: HospitalSetSaveData) {
        if (hospitalInfo.id) {// 判断是否有id 有就是修改
            return request.put<any, any>(`/admin/hosp/hospitalSet/update`, hospitalInfo)
        } else {// 没有id就是添加
            return request.post<any, any>(`/admin/hosp/hospitalSet/save`, hospitalInfo)
        }
    },
    // GET /admin/hosp/hospitalSet/sendSignKey/{id}
    // 发送SignKey

    // GET /admin/hosp/hospitalSet/{page}/{limit}
    // 获取分页列表
    getPageList({ page, limit, hosname = '', hoscode = '' }: HospitalPageListData) {
        return request.get<any, HospitalListData>(`/admin/hosp/hospitalSet/${page}/${limit}?hosname=${hosname}&hoscode=${hoscode}`)
    }
}